package com.medica.ledproject.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.medica.ledproject.common.HttpClientUtil;
import com.medica.ledproject.entity.paramerBeans.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author xiaona
 * @date 2024/6/25
 * @description TODO
 */
@CrossOrigin
@RestController
@RequestMapping("/IPPBX")
@Tag(name = "话务台接口")
public class IPPBxController {


    @Operation(summary = "话务台登录")
    @ApiOperationSupport(order = 1)
    @PostMapping(value = "/login")
    public JSONObject login( @RequestBody Loginparm loginparm){

        return HttpClientUtil.loginS(loginparm.getName(),loginparm.getPassword());
//        return  JsonData.login();

    }
    @Operation(summary = "上传音乐文件")
    @ApiOperationSupport(order = 1)
    @PostMapping(value = "/UploadMusic")
    @ResponseBody
    public JSONObject UploadMusic(String Authorization, MultipartFile file){

        return HttpClientUtil.uploadMusic(file,Authorization);
//        return  JsonData.UploadMusic();

    }
    @Operation(summary = "获取音乐列表")
    @ApiOperationSupport(order = 2)
    @PostMapping(value = "/getMusicList")
    @ResponseBody
    public JSONObject getMusicList(@RequestBody ListParm listRes){

        return HttpClientUtil.getMusicList(listRes.getAuthorization(),listRes.getPage(),listRes.getPageSize());
//        return  JsonData.getMusicList();

    }

    @Operation(summary = "删除多条音乐")
    @ApiOperationSupport(order = 3)
    @PostMapping(value = "/delMusic")
    @ResponseBody
    public JSONObject delMusic(@RequestBody DelParm delParm){

        return HttpClientUtil.delMusic(delParm.getAuthorization(),delParm.getIds());
//        return  JsonData.delMusic();

    }
    @Operation(summary = "添加音乐到播放列表")
    @ApiOperationSupport(order = 4)
    @PostMapping(value = "/addToPlay")
    @ResponseBody
    public JSONObject addToPlay(@RequestBody AddPlayParm addPlayParm){

        return HttpClientUtil.addToPlay(addPlayParm.getName(),addPlayParm.getMusicIds(),addPlayParm.getAuthorization());
//        return  JsonData.addToPlay();
    }
    @Operation(summary = "获取播放列表")
    @ApiOperationSupport(order = 5)
    @PostMapping(value = "/getPlayList")
    @ResponseBody
    public JSONObject getPlayList(@RequestBody ListParm listRes){

        return HttpClientUtil.getPlayList(listRes.getAuthorization(),listRes.getPage(),listRes.getPageSize());
//        return  JsonData.getPlayList();
    }

    @Operation(summary = "删除多条播放列表")
    @ApiOperationSupport(order = 6)
    @PostMapping(value = "/delPlayList")
    @ResponseBody
    public JSONObject delPlayList(@RequestBody DelParm delParm){

        return HttpClientUtil.delPlayList(delParm.getAuthorization(),delParm.getIds());
//        return  JsonData.delPlayList();
    }
    @Operation(summary = "获取分机列表")
    @ApiOperationSupport(order = 7)
    @PostMapping(value = "/getPhoneList")
    @ResponseBody
    public JSONObject getPhoneList(@RequestBody ListParm listRes){

        return HttpClientUtil.getPhoneList(listRes.getAuthorization(),listRes.getPage(),listRes.getPageSize());
//        return  JsonData.getPhoneList();
    }
    @Operation(summary = "创建任务，播放音乐")
    @ApiOperationSupport(order = 8)
    @PostMapping(value = "/palyMusic")
    @ResponseBody
    public JSONObject palyMusic(@RequestBody TaskParm taskParm){

        return HttpClientUtil.palyMusic(taskParm.getAuthorization(),taskParm.getPlayListID(),taskParm.getCycleCount(),taskParm.isHangupAll(),taskParm.getExtensions());
//        return  JsonData.palyMusic();
    }
    @Operation(summary = "获取任务列表")
    @ApiOperationSupport(order = 9)
    @PostMapping(value = "/getTaskList")
    @ResponseBody
    public JSONObject getTaskList( String authorization){

        return HttpClientUtil.getTaskList(authorization);
//        return  JsonData.getTaskList();
    }
    @Operation(summary = "删除任务")
    @ApiOperationSupport(order = 10)
    @Parameter(name = "authorization", description = "toeken", required = true, example = "")
    @Parameter(name = "uuid", description = "任务id", required = true, example = "[9,7,4]")
    @PostMapping(value = "/delTask")
    @ResponseBody
    public JSONObject delTask(@RequestBody DelParm delParm){

        return HttpClientUtil.delTask(delParm.getAuthorization(),delParm.getIds());
//        return  JsonData.delTask();
    }
    @Operation(summary = "post请求")
    @ApiOperationSupport(order = 11)
    @PostMapping(value = "/post")
    @ResponseBody
    public JSONObject post(@RequestBody PostParm postParm){
        return HttpClientUtil.post(postParm.getUrl(),JSONObject.parseObject(postParm.getJson()),postParm.getAuthorization());

    }
    @Operation(summary = "get请求")
    @ApiOperationSupport(order = 12)
    @PostMapping(value = "/get")
    @ResponseBody
    public JSONObject get(String authorization,String parm,String url){
        return HttpClientUtil.gets(url,authorization,parm);

    }
}
